home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapargreplacer.py < prev    next >
Text File  |  2004-01-05  |  3KB  |  79 lines

  1. """
  2. QuArK  -  Quake Army Knife
  3. """
  4.  
  5. #$Header: /cvsroot/quark/runtime/plugins/mapargreplacer.py,v 1.5 2003/12/18 21:51:46 peter-b Exp $
  6.  
  7. Info = {
  8.    "plug-in":       "Arg Replacer",
  9.    "desc":          "",
  10.    "date":          "6 Sep 99",
  11.    "author":        "Decker",
  12.    "author e-mail": "decker@post1.tele.dk",
  13.    "quark":         "Version 5.10"
  14. }
  15.  
  16. from quarkpy.maputils import *
  17. import quarkpy.mapduplicator
  18.  
  19. class ArgReplacer(quarkpy.mapduplicator.DuplicatorManager):
  20.  
  21.     Icon = (ico_dict['ico_mapdups'], 2)
  22.  
  23.     def filterspecs(self, specs):
  24.         "Removes MACRO and ORIGIN if they exists in the dictspec.keys() array"
  25.         replacerspecs = []
  26.         for i in specs:
  27.            if (not ((i == "macro") or (i == "origin"))):
  28.               replacerspecs = replacerspecs + [i]
  29.         return replacerspecs
  30.  
  31.     def searchandreplace(self, item, replacerspecs):
  32.         for r in replacerspecs:
  33.            searchstring = '%' + r + '%'
  34.            for key in item.dictspec.keys():
  35.               item[key] = item[key].replace(searchstring, self.dup.dictspec[r])
  36.               newkey = key.replace(searchstring, self.dup.dictspec[r])
  37.               if (newkey != key):
  38.                  keyvalue = item[key]
  39.                  item[key] = None
  40.                  item[newkey] = keyvalue
  41.  
  42.     def replace(self, items, replacerspecs):
  43.         for i in items:
  44.            if ((i.type == ':g') or (i.type == ':d')):
  45.               self.replace(i.subitems, replacerspecs)
  46.            elif (i.type == ':e' or i.type == ':b'):
  47.               self.searchandreplace(i, replacerspecs)
  48.  
  49.     def buildimages(self, singleimage=None):
  50.         items = []
  51.         if ((singleimage is None) or (singleimage == 0)):
  52.            if (self.dup.subitems is not None):
  53.               # why wont a "items = self.dup.subitems.copy()" work?
  54.               for i in self.dup.subitems:
  55.                  items.append(i.copy())
  56.               replacerspecs = self.filterspecs(self.dup.dictspec.keys())
  57.               self.replace(items, replacerspecs)
  58.         return items
  59.  
  60. quarkpy.mapduplicator.DupCodes.update({
  61.   "arg replacer":            ArgReplacer,
  62. })
  63.  
  64. # ----------- REVISION HISTORY ------------
  65. #
  66. # $Log: mapargreplacer.py,v $
  67. # Revision 1.5  2003/12/18 21:51:46  peter-b
  68. # Removed reliance on external string library from Python scripts (second try ;-)
  69. #
  70. # Revision 1.4  2001/10/22 10:21:59  tiglari
  71. # live pointer hunt, revise icon loading
  72. #
  73. # Revision 1.3  2001/06/24 14:47:58  decker_dk
  74. # Can now also replace specific-names.
  75. #
  76. # Revision 1.2  2000/06/03 10:25:30  alexander
  77. # added cvs headers
  78. #
  79.